from crm.db.dbcrm_handle import DbHandle


class DbCustomerAssign:

    def __init__(self):
        self.dbhandle = DbHandle()

    # 添加客户
    def insert_customer_info(self, customerNo):
        self.dbhandle.update_data("insert into customer_info value(customerNO=%s)",[customerNo])

    # 恢复客户分配
    def put_customer_idnull(self,cusname):
        self.dbhandle.update_data("update  customer_info set user_id=Null where customer_name='{}'".format(cusname))

    # 查询客户分配是否成功
    def sec_customer_info(self,cusname,userID):
        res=self.dbhandle.search_data("select * from customer_info where customer_name=%s and user_id=%s",
                                      [cusname,userID])
        if res == ():
            return None
        else:
            res_cus=list(res[0].values()) #返回第一条数据
            return res_cus

    #删除客户
    def del_customer_info(self,table,customerNo):
        self.dbhandle.update_data("delete from %s where customerNO='{}'".format(table,customerNo))

    # 删除多条客户信息
    def del_customers_info_lst(self, table,lst):
        for no in lst:
            self.del_customer_info(table,no)



# if __name__ == '__main__':
#     db_customer=DbCustomerAssign()
#     db_customer.put_customer_idnull('林好美')
